const { Service } = require('egg');

class MemoService extends Service {
    /**
     * 保存备忘录数据
     */
    async create({
        platform,
        task,
        benjin,
        is_return_benjin,
        yongjin,
        is_return_yongjin,
        mark,
    }) {
        let sql =
            'insert into memo (platform, task, benjin, is_return_benjin, yongjin, is_return_yongjin, mark) values (?, ?, ?, ?, ?, ?, ?)';
        let params = [
            platform,
            task,
            benjin,
            is_return_benjin,
            yongjin,
            is_return_yongjin,
            mark,
        ];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }

    async readList() {
        let sql = 'select * from memo';
        let res = await this.app.mysql.query(sql);
        return res;
    }

    async findById(id) {
        let sql = 'select * from memo where id = ?';
        let params = [id];
        let res = await this.app.mysql.query(sql, params);
        return res[0];
    }

    async update(obj) {
        let sql =
            'update memo set is_return_benjin = ?, is_return_yongjin = ?, mark = ? where id = ?';
        let params = [
            obj.is_return_benjin,
            obj.is_return_yongjin,
            obj.mark,
            obj.id,
        ];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }

    async destroy(id) {
        let sql = 'delete from memo where id = ?';
        let params = [id];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }
}

module.exports = MemoService;
